{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'我': 6, '他': 9, '的': 38}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list_text = ['我','他','的']\n",
    "file_text = 'text.txt'\n",
    "\n",
    "def total_text(file,text_key,encoding='UTF8'):\n",
    "    key_dict = {}\n",
    "    with open(file) as f:\n",
    "        text = f.read()\n",
    "        # 去掉换行符 \\n\n",
    "        text.replace('\\n','')\n",
    "        for t in list_text:\n",
    "            key_dict[t] = text.count(t)\n",
    "        return key_dict\n",
    "\n",
    "\n",
    "total_text(file_text,list_text)\n"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "ff79ebfcf6806606a412477be2872c3ec52671763ecb054ca3010c66083164a3"
  },
  "kernelspec": {
   "display_name": "Python 3.8.3 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
